package com.zan.pattern.responsibility;

/**
 * @Author Zan
 * @Create 2024/4/27 10:48
 * @Description : 抽象处理者类
 * @ClassName: Handler
 */
public abstract class Handler {

    protected static final int NUM_ONE = 1;
    protected static final int NUM_THREE = 3;
    protected static final int NUM_SEVEN = 7;     ;

    // 该领导处理的请假天数区间
    private int numStart;
    private int numEnd;

    // 声明后继者（声明上级领导）
    private Handler nextHandler;

    public Handler(int numStart) {
        this.numStart = numStart;
    }

    public Handler(int numStart, int numEnd) {
        this.numStart = numStart;
        this.numEnd = numEnd;
    }

    // 设置上级领导对象
    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }

    // 各级领导处理请假条的方法
    protected abstract void handlerLeave(LeaveRequest request);

    // 提交请假条
    public void submit(LeaveRequest request) {
        // 该领导先进行审批
        this.handlerLeave(request);
        if (this.nextHandler != null && request.getNum() > this.numEnd) {
            // 说明有上级领导，并且他自己不能审批了
            this.nextHandler.submit(request); // 传递给上级领导
        } else {
            System.out.println("流程结束！");
        }
    }
}
